package com.ruoyi.web.controller.my;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kiku.domain.MyTravelDiary;
import com.ruoyi.kiku.service.IMyTravelDiaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 旅行日记Controller
 *
 * @author TT
 * @date 2025-08-23
 */
@RestController
@RequestMapping("/kiku/diary")
public class MyTravelDiaryController extends BaseController
{
    @Autowired
    private IMyTravelDiaryService myTravelDiaryService;

    /**
     * 查询旅行日记列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyTravelDiary myTravelDiary)
    {
        startPage();
        List<MyTravelDiary> list = myTravelDiaryService.selectMyTravelDiaryList(myTravelDiary);
        return getDataTable(list);
    }

    /**
     * 导出旅行日记列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:export')")
    @Log(title = "旅行日记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyTravelDiary myTravelDiary)
    {
        List<MyTravelDiary> list = myTravelDiaryService.selectMyTravelDiaryList(myTravelDiary);
        ExcelUtil<MyTravelDiary> util = new ExcelUtil<MyTravelDiary>(MyTravelDiary.class);
        util.exportExcel(response, list, "旅行日记数据");
    }

    /**
     * 获取旅行日记详细信息
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myTravelDiaryService.selectMyTravelDiaryById(id));
    }

    /**
     * 新增旅行日记
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:add')")
    @Log(title = "旅行日记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyTravelDiary myTravelDiary)
    {
        return toAjax(myTravelDiaryService.insertMyTravelDiary(myTravelDiary));
    }

    /**
     * 修改旅行日记
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:edit')")
    @Log(title = "旅行日记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyTravelDiary myTravelDiary)
    {
        return toAjax(myTravelDiaryService.updateMyTravelDiary(myTravelDiary));
    }

    /**
     * 删除旅行日记
     */
    @PreAuthorize("@ss.hasPermi('kiku:diary:remove')")
    @Log(title = "旅行日记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myTravelDiaryService.deleteMyTravelDiaryByIds(ids));
    }
}
